#include <iostream>
#include <string>
using namespace std;
int jud(int x ){
	int  temp = x;
	int tt = 10000000;
	while(temp != 0){
//		int t = temp *10;

		if(temp / tt != (temp %10)) return 0;
		else {
			temp %= tt;
			temp /= 10;
			tt /= 100;
		}
	}
	cout << x <<endl;
	return 1;
}
int days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int legal(int x){
	int day = x %100,mon = x/100 %100,year = x / 10000;
	int rn = 0;
	if( year % 400 == 0 || (year % 100 != 0 &&year % 4 == 0)) rn = 1;
	if(rn == 1) days[2-1] ++;
	if(mon <1 ||mon > 12 || day >days[mon-1] || day < 1) return 0;
	else return 1;
}
int adds[4] = {11000,100100,1000010,10000001};
int nexts(int x){
	int  t = x;
	for(int i=0;i<4;i++){
		t = x + adds[i];
		
		if(legal(t) ){
			break;
		}
	}
	return t;
	
}
int main()
{
	// 请在此输入您的代码
	// string s;
	int s;
	cin >>s;
	int cnt = 0;
	while (cnt < 2){
		s = nexts(s);			
//		if(legal(s))
		if(jud(s)) {cnt ++;}
	}
	return 0;
}
